#if !defined(APP_DEVICE_H)
#define APP_DEVICE_H
#include "app_message.h"
#include "app_buffer.h"
#include "pthread.h"
//设备类型
typedef enum{
    DEV_GENERAL,
    DEV_SERIAL,
    DEV_USB,
}DeviceType;

//包含设备相关函数（由子模块或者其他模块实现）的结构体
typedef struct
{
    //读取设备的后置函数
    int (*post_read)(Device *device,char *data,int len);
    //写入设备的前置函数
    int (*pre_write)(Device *device,char *data,int len);
    int (*send_msg)(Device *device,char *data,int len);
}DeviceFunc;


typedef struct 
{
    char *filname;
    int fd;
    ConnectionType conn_type;
    DeviceType dev_type;
    Buffer *read_buffer;
    Buffer *write_buffer;
    pthread_t read_thread;
    int running;
    DeviceFunc *func;
long last_write_time; // 最后一次写入数据的时间
}Device;

//初始化设备
Device *app_device_init(char *filname);
//启动设备
int app_device_start(Device *device);

//停止设备
int app_device_stop(Device *device);
//关闭释放设备
void app_device_close(Device *device);



#endif // APP_DEVICE_H
